package com.dyz.swordFingerOffer;

/**
 * @author: daiyizheng
 * @date: 2021/6/11 19:26
 * @description:
 */
public class IsSymmetrical28 {
    boolean isSymmetrical(TreeNode pRoot) {
        if(pRoot==null){
            return true;
        }
        //深度遍历
        return dfs(pRoot.left, pRoot.right);

    }

    private boolean dfs(TreeNode left, TreeNode right){
        if(left==null && right==null){
            return true;
        }
        if(left==null || right==null){
            return false;
        }

        if(left.val!=right.val){
            return false;
        }
        return dfs(left.left, right.right) && dfs(left.right, right.left);
    }
}
